﻿using Microsoft.CodeAnalysis;

namespace Beeflys.Generator
{
    public class UNamespaceInfo
    {
        public static void Parse(INamespaceSymbol namespaceSymbol)
        {
            var namespaceInfo = new UNamespaceInfo(namespaceSymbol);
            
            namespaceInfo.Parse();
        }

        public UNamespaceInfo(INamespaceSymbol namespaceSymbol)
        {
            this.namespaceSymbol = namespaceSymbol;
        }

        private INamespaceSymbol namespaceSymbol;

        public string Namespace { get; private set; }
        
        private void Parse()
        {
            this.Namespace = namespaceSymbol.ToString();
            var members = this.namespaceSymbol.GetTypeMembers();
            foreach (INamedTypeSymbol typeSymbol in members)
            {
                if (typeSymbol.IsNamespace)
                {
                   continue;
                }

                string fullName = typeSymbol.ToString();
                if (Mapper.Contains(fullName))
                {
                    continue;
                }

                UTypeInfo typeInfo = new UTypeInfo(typeSymbol);
                typeInfo.Parse();
                
                Mapper.Add(typeInfo);
            }
        }
    }
}